<?php

/**
 * 支付模块
 * @copyright (c) 2013, Mr.Wang
 * @author Mr.Wang <281762391@qq.com>
 */
class EmptyAction extends Action {

    public $pay_service;

    public function index(){
        
    }
    function _initialize() {
        importModule('Pay.Service.PayService');
        $this->pay_service = new PayService();
        $this->assign("waitSecond", 5000);
    }

    public function to() {
        $pay_id = $_REQUEST['sn'];
        $payContent = service("Pay")->pay_service_get($pay_id);
        $data = M('Pay')->where("pay_id = '{$pay_id}'")->find();
        $jumpUrl = U("Trade/Show", array("id" => $data['connect_id'], "connect_type" => $data['connect_type']));
        $this->assign("jumpUrl", $jumpUrl);
        if ($payContent['status'] == true) {
            if ($payContent['data']['show'] == 'HTML') {
                $this->assign('payContent', $payContent['data']['showData']);
                $this->display('Pay:dopay');
            } else {
                if ($payContent['data']['url']) {
                    $this->assign('jumpUrl', $payContent['data']['url']);
                }
                $this->success($payContent['msg']);
            }
        } else {
            $this->error($payContent['msg']);
        }
    }

    public function confirm() {
        $param = $_REQUEST;
        $_POST = $this->paypal();
        $param['payMode'] = ucfirst(trim(MODULE_NAME));
        if ($param['hide'] == "1") {
            $param['payAdmin'] = true;
        }
        $confirmArr = service("Pay")->pay_service_confirm($param);
        if ($param['payAdmin']) {
            echo $confirmArr['data']['content'];
        } else {
            $this->assign("waitSecond", 5000);
            $this->assign("jumpUrl", D("Pay")->jumpUrl($confirmArr));
            if ($confirmArr['status']) {
                $this->success($confirmArr['msg']);
            } else {
                $this->error($confirmArr['msg']);
            }
        }
    }

    function paypal() {
        return array(
            'mc_gross' => '0.10',
            'invoice' => 'PayTest20130525_1_00000011',
            'protection_eligibility' => 'Ineligible',
            'payer_id' => '6FRPZR93B2E6J',
            'tax' => '0.00',
            'payment_date' => '01:27:24 May 25, 2013 PDT',
            'payment_status' => 'Completed',
            'charset' => 'gb2312',
            'first_name' => '松林',
            'mc_fee' => '0.10',
            'notify_version' => '3.7',
            'custom' => '',
            'payer_status' => 'verified',
            'business' => 'leipekfa@msn.com',
            'quantity' => '1',
            'verify_sign' => 'ARyNDMbKwa-zLx7AtfPa-etrhyTVAQtRxFy0zR7aL8N75-cA7UBt6AXK',
            'payer_email' => '934597281@qq.com',
            'txn_id' => '69E76274912797456',
            'payment_type' => 'instant',
            'last_name' => '陈',
            'receiver_email' => 'leipekfa@msn.com',
            'payment_fee' => '0.10',
            'receiver_id' => 'G5BENZXSNYHXG',
            'txn_type' => 'web_accept',
            'item_name' => 'PayTest20130525_1_00000011',
            'mc_currency' => 'USD',
            'item_number' => '',
            'residence_country' => 'CN',
            'handling_amount' => '0.00',
            'transaction_subject' => 'PayTest20130525_1_00000011',
            'payment_gross' => '0.10',
            'shipping' => '0.00',
            'ipn_track_id' => 'f2be4ea8ddfcb',
            'pay_id' => '11',
            'hide' => '1',
            '_URL_' =>
            array(
                0 => 'pay',
                1 => 'paypal',
                2 => 'confirm',
                3 => 'pay_id',
                4 => '11',
                5 => 'hide',
                6 => '1',
            ),
            'payMode' => 'paypal',
            'payAdmin' => true,
        );
    }

}

?>
